//
//  NHTPushService.h
//  PlantGrowthLamp
//
//  Created by NHT on 2023/10/28.
//

#import <Foundation/Foundation.h>
// iOS10 注册 APNs 所需头文件 10之前不能导入
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif

NS_ASSUME_NONNULL_BEGIN

@interface NHTPushService : NSObject

/// 创建单利对象
+(instancetype)shareNHTPush;

///处理后的deviceToken
@property (nonatomic,copy) NSString  *deviceTokenFinal;
///原始的deviceToken
@property (nonatomic,copy) NSData  *deviceTokenOriginal;

///用户配置的链接地址，可不配置有默认值
@property (nonatomic,copy) NSString  *userSocketAdress;


/// 注册推送服务
/// - Parameters:
///   - delegate: 推送代理，必须为Appdelegate
///   - resultBlock: 消息回调,messageType------0：注册结果；1推送消息；2socket消息；
-(void)NHTPushRegisterPushMessageBlock:(void (^)(NSDictionary *messageDic,NSInteger messageType))resultBlock;

/// 注册推送服务
/// - Parameters:
///   - delegate: 推送代理，必须为Appdelegate
///   - options: 推送提示类型，比如 UNAuthorizationOptionSound | UNAuthorizationOptionAlert
///   - resultBlock: 消息回调,messageType------0：注册结果；1推送消息；2socket消息；
-(void)NHTPushRegisterPushType:(UNAuthorizationOptions)options pushMessageBlock:(void (^)(NSDictionary *messageDic,NSInteger messageType))resultBlock;

/// 连接socket，连接成功后，消息会自动通过socket接收到，不再通过推送
/// - Parameter isProduction: 是否是生产环境
/// - Parameter resultBlock: socket连接状态 0：连接中；1连接成功；2关闭中；3连接失败、已关闭；
-(void)NHTPushSocketOpen:(BOOL)isProduction resultBlock:(void (^)(NSInteger state))resultBlock;

/// 关闭socket连接
-(void)NHTPushSocketClose;


///注册推送成功
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
///注册推送失败
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

///收到推送消息
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;

///收到推送消息 int是为了适配uniapp
-(void)applicationUniApp:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(NSInteger))completionHandler;


@end

NS_ASSUME_NONNULL_END
